<?php
/*
 * Data Explorer: Search Tags
 *      "tags.php"
 *
 * last modified: 10/19/10
 * author: James Duran
 *
 * description: echo's back a json array of search tags corresponding
 *              to the get input ds='', which represents the name
 *              of a dataset.
 *
 * comments: this file still needs to be fully commented and reviewed,
 *           providing an error message/default option for invalid
 *           get input.
 */

require_once 'mysqlDriver.php';
// get the parameter specifying the current dataset to generate tags for
$ds = $_GET['ds'];

// airportsGenerateTags:
//
// retrieves faa database information from mysql database.
// The result is then encoded into a json array and echoed back.
function airportsGenerateTags() {
    $_array = array();
    $_result = sqlSelect("SELECT * FROM `faa_airport_loc_list`" .
        " where name like '%" . $_GET['term'] . "%'" .
        " or code like '%"  .$_GET['term'] . "%'" .
        " or city like '%"  .$_GET['term'] . "%'" .
        " or state like '%"  .$_GET['term'] . "%' LIMIT 1");
    while($_row = mysql_fetch_assoc($_result)) {
//        $_arrayRow = $_row['code'] .
//	', ' . $_row['name'] .
//	', ' . $_row['city'] .
//	', ' . $_row['state'];
        $_arrayRow['value'] = $_row['code'] .
    ', ' . $_row['name'] .
    ', ' . $_row['city'] .
    ', ' . $_row['state'];

    $_arrayRow['id']['latitude'] = $_row['latitude'];
     $_arrayRow['id']['longitude'] = $_row['longitude'];
        array_push($_array, $_arrayRow);
    }
    mysql_free_result($_result);
    echo json_encode($_array);
}

// generateDefaultTags:
//
// generate default tags for test purposes.
function generateDefaultTags() {
    $_array = array("testing 1", "testing 2", "another tag", "more tags..");
    echo json_encode($_array);
}

if($ds == "FAA Web Service")
    airportsGenerateTags();
else
    generateDefaultTags();
